package com.taoym.voucher.common.enums;

import com.taoym.voucher.common.utils.TimeUtil;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @coder taoym
 * @datetime 2021/6/5 9:31
 * @desc 用户账单日期枚举类
 */
@Getter
public enum DateConditionEnum implements EnumsCommon {

    TODAY(1, "今天"),
    WEEK(2, "本周"),
    MONTH(3, "本月"),
    PREV_MONTH(4, "上月"),
    YEAR(5, "近三月"),
    ;

    private final Integer code;
    private final String msg;

    DateConditionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getMsg(Integer code) {
        for (DateConditionEnum value : values()) {
            if (code.equals(value.code)) {
                return value.msg;
            }
        }
        return null;
    }

    public static Map<String, LocalDateTime> getDateLocalDate(Integer code) {

        Map<String, LocalDateTime> map = new HashMap<>(1);
        if(ObjectUtils.isEmpty(code)){
            return map;
        }

        switch (code) {
            case 1: {
                map.put("start", TimeUtil.dayStartTime());
                map.put("end", LocalDateTime.now());
                break;
            }
            case 2: {
                map.put("start", TimeUtil.weekStartTime());
                map.put("end", LocalDateTime.now());
                break;
            }
            case 3: {
                map.put("start", TimeUtil.getMonthStartTime());
                map.put("end", LocalDateTime.now());
                break;
            }
            case 4: {
                map.put("start", TimeUtil.getMonthStartTime(LocalDate.now().plusMonths(-1)));
                map.put("end", TimeUtil.getMonthEndTime(LocalDate.now().plusMonths(-1)));
                break;
            }
            case 5: {
                map.put("start", TimeUtil.getMonthStartTime(LocalDate.now().plusMonths(-3)));
                map.put("end", LocalDateTime.now());
                break;
            }
            default: {
                break;
            }

        }
        return map;
    }
}
